home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / ExampleLibrary / Sources / ExampleClass.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  4.0 KB  |  151 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ExampleClass.h
  3.  
  4.     Contains:    Declarations for the TExampleClass
  5.  
  6.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __EXAMPLECLASS__
  12. #define __EXAMPLECLASS__
  13.  
  14.  
  15. // the functionset ID for the example library
  16. #define kExampleFunctionSet "appl:exam$ExampleFSet,1.2"
  17.  
  18. #ifndef __LIBRARYMANAGER__
  19. #include <LibraryManager.h>
  20. #endif
  21.  
  22. #ifdef __cplusplus
  23.  
  24. #ifndef __LIBRARYMANAGERCLASSES__
  25. #include <LibraryManagerClasses.h>
  26. #endif
  27.  
  28. typedef unsigned long    ulong;
  29. typedef char*            (* _CDECL HelloCPtr)(ulong*);
  30. typedef pascal Ptr        (*HelloPPtr)(ulong&);
  31.  
  32. //
  33. // If __SCLIBRARY__ is defined then that means not only are we compiling with
  34. // SCpp, but we also want to use Symantec calling conventions. In this case
  35. // undefine _CDECL so that Symantec C++ calling conventions will be used. The
  36. // library will not be usable from the CPlus version of LibraryManagerTest1
  37. // tool in this case.
  38. //
  39. // Note that the destructor still uses _cdecl calling conventions if 
  40. // __SCLIBRARY__ is defined because the destructor had already been
  41. // declared as _cdecl in TSCDynamic.
  42. //
  43. #if __SCLIBRARY__
  44.     #define _CDECL2
  45. #else
  46.     #define _CDECL2 _CDECL
  47. #endif
  48.  
  49. /**********************************************************************
  50. ** class TExampleClass
  51. ***********************************************************************/
  52.  
  53. #define kTExampleClassID    "appl:exam$TExampleClass,1.2"
  54.  
  55. #if __SCLIBRARY__
  56. class TExampleClass : public TSCDynamic
  57. #else
  58. class TExampleClass : public TDynamic
  59. #endif
  60. {
  61.     public:
  62.                                 _CDECL2 TExampleClass();
  63.         virtual                    ~ _CDECL TExampleClass();
  64.         
  65.         // New Methods
  66.  
  67.         virtual char*             _CDECL2 GetObjectName() const;
  68.         virtual void             _CDECL2 SetObjectName(char *theName);
  69.  
  70.         virtual    void            _CDECL2 DoThisAndThat();
  71.         virtual    void            _CDECL2 DoThat();
  72.  
  73.         virtual void            _CDECL2 SetGlobalInt(long theValue);
  74.         virtual long            _CDECL2 GetGlobalInt();
  75.  
  76.         // Public non-virtual function
  77.         // Dynamically exported by using ExportFunction
  78.         void                    _CDECL2 GetGlobalRef(long*&);
  79.  
  80.         // Public static function
  81.         // Dynamically exported by the ExportFunction
  82.         static Boolean            _CDECL2 Test(ulong test);
  83.         static Boolean            _CDECL2 Test(char* test);
  84.         
  85.     private:        
  86.         char *fName;
  87.         
  88.         // static gExampleClassCount counts the number of instances
  89.         static long                gExampleClassCount;
  90. };
  91.  
  92.  
  93. extern "C" char* HelloC(ulong*);
  94. ulong _CDECL Goodbye();
  95.  
  96. //
  97. // The THINK C++ compiler does not automically upper case pascal function
  98. // names so we need to declare them as upper case.
  99. //
  100. #if defined(THINK_CPLUS)
  101.     pascal Ptr HELLOPASCAL(ulong& theHelloTicks);
  102.     pascal ulong GOODBYEPASCAL();
  103. #else
  104.     pascal Ptr HelloPascal(ulong& theHelloTicks);
  105.     pascal ulong GoodbyePascal();
  106. #endif
  107.  
  108. //
  109. // Unfortunately, Symantec C++ does not handle overloaded _cdecl functions,
  110. // even though it handles overloaded _cdecl methods, so we resort to a hack
  111. // here.  If we're compiling with Symantec - we use the mangled names of the
  112. // "C" Functions to allow the link to work.  Of course, if we compile 
  113. // ExampleClass with Symantec C++, and link it with Symantec C++ this problem
  114. // doesn't exist.
  115. //
  116. #if (defined(THINK_CPLUS) || defined(__SC__)) && !__SCLIBRARY__
  117.     #define kHelloRef    Hello__FRUl
  118.     #define kHelloPtr    Hello__FPUl
  119.     
  120.     char* _CDECL kHelloRef(ulong&);
  121.     char* _CDECL kHelloPtr(ulong*);
  122. #else
  123.     #define kHelloRef    Hello
  124.     #define kHelloPtr    Hello
  125.     
  126.     char* Hello(ulong&);
  127.     char* Hello(ulong*);
  128. #endif
  129.  
  130. #else
  131.  
  132. typedef void TExampleClass;
  133.  
  134. /* Inline message dispatching code */
  135. #define JSRA1          0x4e91
  136. #define dispatchMessage(routineID)        \
  137.     {0x2057,0x2050,0x2268,4*##routineID,JSRA1}
  138.  
  139. void ExDestructor(TExampleClass* this) = dispatchMessage(1);
  140. char* ExGetObjectName(TExampleClass* this) = dispatchMessage(9);
  141. void ExSetObjectName(TExampleClass* this, char *theName) = dispatchMessage(10);
  142. void ExDoThisAndThat(TExampleClass* this) = dispatchMessage(11);
  143. void ExDoThat(TExampleClass* this) = dispatchMessage(12);
  144. void ExSetGlobalInt(TExampleClass* this, long theValue) = dispatchMessage(13);
  145. long ExGetGlobalInt(TExampleClass* this) = dispatchMessage(14);
  146.  
  147. char* Hello();
  148.  
  149. #endif
  150. #endif
  151.